package com.x.filters;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;

/**
 * ClassName: LifeCycleFilter
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.08.30 14:34
 */

@WebFilter(urlPatterns = {"/ServletFilter"},
        initParams = {@WebInitParam(name = "dateTimePattern", value = "yy:MM:dd HH:mm:ss")}
)
public class LifeCycleFilter implements Filter {

    public LifeCycleFilter() {
        System.out.println("Filter构造方法");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter初始化");
        System.out.println(filterConfig.getInitParameter("dateTimePattern"));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("Filter放行");
    }

    @Override
    public void destroy() {
        System.out.println("Filter销毁");
    }
}
